#ifndef AVIINTERFACE_H
#define AVIINTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <mmreg.h>
#include "basetype.h"

#define AVIFF_ERR_OK           0

#define AVIFF_ERR_SIZELIM      1     /* The write of the data would exceed
                                      the maximum size of the AVI file.
                                      This is more a warning than an error
                                      since the file may be closed safely */

#define AVIFF_ERR_OPEN         2     /* Error opening the AVI file - wrong path
                                      name or file nor readable/writable */

#define AVIFF_ERR_READ         3     /* Error reading from AVI File */

#define AVIFF_ERR_WRITE        4     /* Error writing to AVI File,
                                      disk full ??? */

#define AVIFF_ERR_WRITE_INDEX  5     /* Could not write index to AVI file
                                      during close, file may still be
                                      usable */

#define AVIFF_ERR_CLOSE        6     /* Could not write header to AVI file
                                      or not truncate the file during close,
                                      file is most probably corrupted */

#define AVIFF_ERR_NOT_PERM     7     /* Operation not permitted:
                                      trying to read from a file open
                                      for writing or vice versa */

#define AVIFF_ERR_NO_MEM       8     /* malloc failed */

#define AVIFF_ERR_NO_AVI       9     /* Not an AVI file */

#define AVIFF_ERR_NO_HDRL     10     /* AVI file has no has no header list,
                                      corrupted ??? */

#define AVIFF_ERR_NO_MOVI     11     /* AVI file has no has no MOVI list,
                                      corrupted ??? */

#define AVIFF_ERR_NO_VIDS     12     /* AVI file contains no video data */

#define AVIFF_ERR_NO_IDX      13     /* The file has been opened with
                                      getIndex==0, but an operation has been
                                      performed that needs an index */

#define AVIFF_ERR_LAST_FRAME  14

#define AVIFF_BUFFER_TOO_SMALL  15

#define AVIFF_ERR_NO_AUD       16

typedef enum
{
    AVIFF_UNKNOWN_VIDEO_TYPE = 0,
    AVIFF_MPEG4 = 10,
    AVIFF_H263 = 11,
    AVIFF_H264 = 12,
    AVIFF_WMV = 13,
    AVIFF_MJPEGA = 14,
    AVIFF_MJPEGB = 15
} AviffVideoType;

typedef enum
{
    AVIFF_UNKNOWN_AUDIO_TYPE = 0,
    AVIFF_AMR_NB = 20,
    AVIFF_AMR_WB = 21,
    AVIFF_AAC_LC = 22,
    AVIFF_QCELP = 23,
    AVIFF_QCELP_SQCP = 24,
    AVIFF_AACPLUS = 25,
    AVIFF_AMR_WBPLUS = 26,
    AVIFF_MP123 = 27,
    AVIFF_ALAW,
    AVIFF_ULAW,
    AVIFF_ADPCM,
    AVIFF_PCM8_BE,
    AVIFF_PCM16_BE,
    AVIFF_PCM24_BE,
    AVIFF_PCM32_BE,
    AVIFF_PCM8_LE,
    AVIFF_PCM16_LE,
    AVIFF_PCM24_LE,
    AVIFF_PCM32_LE,
    AVIFF_AAC
} AviffAudioType;


typedef enum
{
    AVIFF_FRAME_VIDEO = 0,
    AVIFF_FRAME_AUDIO = 1
}AviffFrameType;


typedef enum
{
    AVIFF_SEEK_PREVIOUS_KEYFRAME = 0,
    AVIFF_SEEK_NEXT_KEYFRAME = 1,
    AVIFF_SEEK_NEAREST_KEYFRAME = 2,
    AVIFF_SEEK_EXACT = 3
} AviffSeekMode;

typedef struct
{
    u16                videoType;    
    u16                frameWidth;
    u16                frameHeight;
    u16                frameRate;
    u32                timeScale;
    u32                videoTrackLength;
    u32                numOfFrames;
    u8                 level;
    u8                 profile;
    u32                startDelay;
    u32                maxBitrate;
    u32                avgBitrate;
    u32                numOfSyncSamples;
    u32                frameSize;
} AVIFF_VideoInfo;

typedef struct
{
    AviffAudioType  audioType;           /* WAVEFORMATEX struct  wFormatTag  */
    u32             audioTrackLength;
    u32             samplingRate;
    u32             extSamplingRate;
    u32             timeScale;
    u16             channelNumber;
    u16             extChannelNumber;
    u32             startDelay;
    u32             maxBitrate;
    u32             avgBitrate;
    u32             sampleSize;
} AVIFF_AudioInfo;


i32 AVIFF_OpenAVIFile( u16 *pFileName, void** pFile );
i32 AVIFF_CloseAVIFile(void *file);
i32 AVIFF_GetAudioInfo(void *file, AVIFF_AudioInfo* pAudioInfo);
i32 AVIFF_GetVideoInfo(void *file,  AVIFF_VideoInfo* pVideoInfo);
i32 AVIFF_ReadAudioFrame(void *file, u8 *pAudioBuffer, u32 *pLen, u32 *pTimestamp);
i32 AVIFF_ReadVideoFrame(void *file, u8 *pVideoBuffer, u32 *pLen, u8* pIsKeyFrame, u32 *pTimestamp);
i32 AVIFF_MediaSeek(void* file, u32* pseektime, AviffSeekMode seek_mode);
i32 AVIFF_FileSize(void* file);


#ifdef __cplusplus
}
#endif
#endif
